from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-08-23 14:13:11.129211
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 23, Aug, 2021
Time: 14:13:16
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.7536
Nobs: 392.000 HQIC: -46.3040
Log likelihood: 4230.40 FPE: 5.41402e-21
AIC: -46.6654 Det(Omega_mle): 4.31579e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.432959 0.095337 4.541 0.000
L1.Burgenland 0.101106 0.049362 2.048 0.041
L1.Kärnten -0.115840 0.024514 -4.725 0.000
L1.Niederösterreich 0.163707 0.106478 1.537 0.124
L1.Oberösterreich 0.139065 0.104650 1.329 0.184
L1.Salzburg 0.285416 0.051761 5.514 0.000
L1.Steiermark 0.020136 0.068684 0.293 0.769
L1.Tirol 0.110128 0.054116 2.035 0.042
L1.Vorarlberg -0.116674 0.048912 -2.385 0.017
L1.Wien -0.013124 0.094424 -0.139 0.889
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.011907 0.221783 0.054 0.957
L1.Burgenland -0.049314 0.114830 -0.429 0.668
L1.Kärnten 0.035112 0.057028 0.616 0.538
L1.Niederösterreich -0.249475 0.247700 -1.007 0.314
L1.Oberösterreich 0.537127 0.243449 2.206 0.027
L1.Salzburg 0.314594 0.120412 2.613 0.009
L1.Steiermark 0.114775 0.159780 0.718 0.473
L1.Tirol 0.306584 0.125889 2.435 0.015
L1.Vorarlberg -0.010749 0.113785 -0.094 0.925
L1.Wien 0.001484 0.219659 0.007 0.995
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.252017 0.048466 5.200 0.000
L1.Burgenland 0.090585 0.025094 3.610 0.000
L1.Kärnten -0.003384 0.012462 -0.272 0.786
L1.Niederösterreich 0.224354 0.054129 4.145 0.000
L1.Oberösterreich 0.165406 0.053200 3.109 0.002
L1.Salzburg 0.038715 0.026313 1.471 0.141
L1.Steiermark 0.010438 0.034916 0.299 0.765
L1.Tirol 0.070668 0.027510 2.569 0.010
L1.Vorarlberg 0.055663 0.024865 2.239 0.025
L1.Wien 0.096600 0.048002 2.012 0.044
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.182497 0.047267 3.861 0.000
L1.Burgenland 0.045733 0.024473 1.869 0.062
L1.Kärnten -0.006832 0.012154 -0.562 0.574
L1.Niederösterreich 0.134053 0.052791 2.539 0.011
L1.Oberösterreich 0.316132 0.051885 6.093 0.000
L1.Salzburg 0.097674 0.025663 3.806 0.000
L1.Steiermark 0.138266 0.034053 4.060 0.000
L1.Tirol 0.074048 0.026830 2.760 0.006
L1.Vorarlberg 0.055710 0.024250 2.297 0.022
L1.Wien -0.037889 0.046815 -0.809 0.418
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.215023 0.094329 2.280 0.023
L1.Burgenland -0.058774 0.048840 -1.203 0.229
L1.Kärnten -0.035474 0.024255 -1.463 0.144
L1.Niederösterreich 0.097663 0.105352 0.927 0.354
L1.Oberösterreich 0.181883 0.103544 1.757 0.079
L1.Salzburg 0.260767 0.051214 5.092 0.000
L1.Steiermark 0.080752 0.067958 1.188 0.235
L1.Tirol 0.122611 0.053543 2.290 0.022
L1.Vorarlberg 0.113819 0.048395 2.352 0.019
L1.Wien 0.025562 0.093426 0.274 0.784
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.025847 0.073488 0.352 0.725
L1.Burgenland 0.026085 0.038049 0.686 0.493
L1.Kärnten 0.050373 0.018896 2.666 0.008
L1.Niederösterreich 0.197788 0.082076 2.410 0.016
L1.Oberösterreich 0.347547 0.080667 4.308 0.000
L1.Salzburg 0.046098 0.039899 1.155 0.248
L1.Steiermark -0.001735 0.052944 -0.033 0.974
L1.Tirol 0.113934 0.041714 2.731 0.006
L1.Vorarlberg 0.061944 0.037703 1.643 0.100
L1.Wien 0.133546 0.072785 1.835 0.067
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187923 0.089509 2.099 0.036
L1.Burgenland 0.021370 0.046344 0.461 0.645
L1.Kärnten -0.057325 0.023016 -2.491 0.013
L1.Niederösterreich -0.121232 0.099969 -1.213 0.225
L1.Oberösterreich 0.193376 0.098254 1.968 0.049
L1.Salzburg 0.031975 0.048597 0.658 0.511
L1.Steiermark 0.299392 0.064486 4.643 0.000
L1.Tirol 0.493559 0.050808 9.714 0.000
L1.Vorarlberg 0.066708 0.045922 1.453 0.146
L1.Wien -0.112898 0.088652 -1.273 0.203
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.159259 0.097502 1.633 0.102
L1.Burgenland -0.006090 0.050483 -0.121 0.904
L1.Kärnten 0.062762 0.025071 2.503 0.012
L1.Niederösterreich 0.194474 0.108896 1.786 0.074
L1.Oberösterreich -0.116425 0.107027 -1.088 0.277
L1.Salzburg 0.244330 0.052937 4.616 0.000
L1.Steiermark 0.152943 0.070244 2.177 0.029
L1.Tirol 0.049418 0.055345 0.893 0.372
L1.Vorarlberg 0.120902 0.050023 2.417 0.016
L1.Wien 0.141805 0.096569 1.468 0.142
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.487220 0.052849 9.219 0.000
L1.Burgenland -0.010810 0.027363 -0.395 0.693
L1.Kärnten -0.009708 0.013589 -0.714 0.475
L1.Niederösterreich 0.197386 0.059024 3.344 0.001
L1.Oberösterreich 0.265904 0.058011 4.584 0.000
L1.Salzburg 0.020295 0.028693 0.707 0.479
L1.Steiermark -0.023364 0.038074 -0.614 0.539
L1.Tirol 0.066338 0.029998 2.211 0.027
L1.Vorarlberg 0.058834 0.027114 2.170 0.030
L1.Wien -0.049453 0.052343 -0.945 0.345
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.017563 0.080233 0.136979 0.130237 0.042206 0.068478 0.003189 0.176847
Kärnten 0.017563 1.000000 -0.057257 0.129661 0.047105 0.067869 0.457202 -0.094163 0.095917
Niederösterreich 0.080233 -0.057257 1.000000 0.285005 0.086166 0.275897 0.014315 0.147994 0.250646
Oberösterreich 0.136979 0.129661 0.285005 1.000000 0.176724 0.291735 0.160590 0.116702 0.135792
Salzburg 0.130237 0.047105 0.086166 0.176724 1.000000 0.128994 0.053582 0.109286 0.048883
Steiermark 0.042206 0.067869 0.275897 0.291735 0.128994 1.000000 0.126483 0.086685 -0.025335
Tirol 0.068478 0.457202 0.014315 0.160590 0.053582 0.126483 1.000000 0.039717 0.119030
Vorarlberg 0.003189 -0.094163 0.147994 0.116702 0.109286 0.086685 0.039717 1.000000 -0.046201
Wien 0.176847 0.095917 0.250646 0.135792 0.048883 -0.025335 0.119030 -0.046201 1.000000